
#include "stdafx.h"
#include "TickTest.h"
#include "LogClass.h"

CTickTest tkTest;

void CTickTest::start(LPCWSTR m)
{
	pos = 0; started = true; add(m);
}

intptr_t CTickTest::add(LPCWSTR m)
{
	if (!started) return -1;
	LARGE_INTEGER tk; QueryPerformanceCounter(&tk);
	intptr_t p = InterlockedExchangeAdd(&pos, 1);
	buf[p].tk = tk; buf[p].msg = m;
	return p;
}

void CTickTest::finish(LPCWSTR m, ITestLogProcesser *pProc)
{
	intptr_t p = add(m); started = false;
	LARGE_INTEGER freq; QueryPerformanceFrequency(&freq);
	for (intptr_t i = 0; i <= p; i++)
	{
		CString v; v.Format(L"%.3f %s", (double)(buf[i].tk.QuadPart - buf[0].tk.QuadPart) * 1000 / freq.QuadPart, buf[i].msg);
		if (!pProc)
			gLog.add((LPCWSTR)v);
		else
			pProc->procLog((LPCWSTR)v);
	}
}
